# 1.导入模块
import requests
from bs4 import BeautifulSoup
import re

# 2. 发送请求,获取疫情首页数据响应对象
response = requests.get('https://ncov.dxy.cn/ncovh5/view/pneumonia')
home_page = response.content.decode()
# print(home_page)

# 通过 ctrl+f 在交互端查找"美国"
# 美国数据在标签里:<script id="getListByCountryTypeService2true">
# 3. 使用BeautifulSoup提取疫情数据
soup = BeautifulSoup(home_page, "lxml")
script = soup.find(id='getListByCountryTypeService2true')
text = script.string
# print(text)

# 4. 使用正则表达式提取字符串

json_str = re.findall(r'(\[.+\])', text)[0]
print(json_str)
